/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.lucava.boatskeeper.server.service;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import java.util.List;
import org.lucava.boatskeeper.client.service.CategoryService;
import org.lucava.boatskeeper.server.dao.MockCategoryDao;
import org.lucava.boatskeeper.shared.dto.CategoryDto;

/**
 *
 * @author glenn
 */
public class CategoryServiceImpl extends RemoteServiceServlet implements CategoryService {

    @Override
    public List<CategoryDto> getCategories() {
        return MockCategoryDao.getAll();
    }

    @Override
    public CategoryDto getCategory(Integer id) {
        return MockCategoryDao.get(id);
    }

    @Override
    public Boolean saveCategory(CategoryDto cat) {

        if (cat.getId() == null) {
            MockCategoryDao.add(cat);
        } else {
            MockCategoryDao.save(cat);
        }

        return true;
    }

    @Override
    public Boolean removeCategory(CategoryDto cat) {
        MockCategoryDao.delete(cat);
        return true;
    }

    @Override
    public Boolean removeCategories(List<Integer> catIds) {

        for (Integer id : catIds) {
            MockCategoryDao.delete(MockCategoryDao.get(id));
        }

        return true;
    }
}
